module two {
	export class LoadingPage extends BaseComponent {
		public constructor() {
			super("LoadingPage");
		}
		public txt_progress: eui.Label;
		public bar: eui.ProgressBar;
		public bar_star: eui.Image;

		private onConfigComplete(): void {
			RES.removeEventListener(RES.ResourceEvent.CONFIG_COMPLETE, this.onConfigComplete, this);

			this.startLoad();
		}

		private startLoad(): void {
			one.loaderManager.maxLoadingThread = 10;

			// let loads = ["games", "sounds", "animations"];
			let loads = ["login_page"];
			this.bar.value = 0;
			this.bar_star.x = 0;
			one.loaderManager.loadGroups(loads, 100, (current: number, total: number) => {
				this.txt_progress.text = `${current}/${total}`;
				this.bar.value = Math.floor(current / total * 100);
				this.bar_star.x = Math.floor(current / total * this.bar.width);

				if (current == total) {
					this.stage.once(egret.TouchEvent.TOUCH_TAP, () => {
						openSound(true, () => {

						});
					}, this);
					openSound(true, () => {

					});

					let _now = new Date().getHours();
					if (_now >= 6 && _now <= 17) {
						RES.getResAsync("Assets/star/starbg_day.jpg", (texture: egret.Texture) => { }, this);
					}
					else {
						RES.getResAsync("Assets/star/starbg_night.jpg", (texture: egret.Texture) => { }, this);
					}

					one.loaderManager.loadGroup("map", 0);

					let shareStarId = getShareStarId();
					if (shareStarId && StarConfig.getConfigById(shareStarId)) {
						User_getMyJewelryProxy.getInstance().send({
						}, (data) => {
							if (data.code == 0) {
								let page = two.changePage("share_open") as ShareOpenPage;
								page.resetStarId(shareStarId);
							}
						})
					}
					else {
						two.changePage("login");
					}
				}
			})
		}

		protected created(): void {
			super.created();

			RES.addEventListener(RES.ResourceEvent.CONFIG_COMPLETE, this.onConfigComplete, this);
			RES.loadConfig("resource/d2.json", "resource/");
		}
	}

	two.setClassMap("loading", "two.LoadingPage");
}